Skip to main content

1678.设计Goal解析器

思路

暴力模拟,判断好左括号就行,左括号下一个是a就加入al,否则加入o

代码

class Solution {
public:
string interpret(string command) {
string res = "";

for (int i = 0 ; i < command.size(); i++) {
if (command[i] == 'G') res += command[i];
else if (command[i] == '(') {
if (command[i + 1] == 'a') res += command.substr(i + 1, 2);
else res += 'o';
}
}
return res;
}
};